<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(items, index) in list" :key="index">
        <div class="icon" v-for="item in items" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" />
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
    <div class="icons-swiper-pagination" slot="pagination"></div>
    <div class="icon-footer">
      <div class="icon-position icon-border">
        <span class="iconfont position-icon">&#xe611;</span>
        <span>定位失败</span>
      </div>

      <div class="icon-position">
        <span class="iconfont">&#xe676;</span>
        <span>必游榜单</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data() {
    return {
      swiperOption: {
        // 轮播图的点
        pagination: '.icons-swiper-pagination'
      }
    }
  },
  computed: {
    list() {
      // 轮播分页
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style scoped lang="stylus">
@import '~styles/varibles.styl';
@import '~styles/mixins.styl';

.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 46%;
}

.icons >>> .swiper-pagination-bullet-active {
  background-color: $bgColor;
}

.icons >>> .swiper-pagination-bullet {
  margin: 0rem 0.1rem;
}

// background-color: green;
.icons {
  padding: 0rem 0.1rem;

  .icons-swiper-pagination {
    padding: 0.1rem 0;
    text-align: center;

    .swiper-pagination-bullet-active {
      display: inline-block;
      margin: 0 0.1rem;
    }
  }

  .icon-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-top: 0.01rem solid #e0e0e0;

    .icon-position {
      width: 50%;
      text-align: center;
      padding: 0.28rem 0;

      .position-icon {
        font-size: 0.36rem;
      }
    }

    .icon-border {
      border-right: 0.01rem solid #e0e0e0;
    }
  }

  .icon {
    position: relative;
    overflow: hidden;
    float: left;
    width: 25%;
    height: 0;
    padding-bottom: 23%;

    // background-color: red;
    .icon-img {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0.44rem;
      // height: 100%;
      box-sizeing: border-box;
      padding: 0.1rem;

      // background-color: blue;
      .icon-img-content {
        display: block;
        margin: 0 auto;
        height: 80%;
        width: 60%;
      }
    }

    .icon-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      color: $darkTextColor;
      text-align: center;
      ellipsis();
    }
  }
}
</style>
